package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;
import com.chaoyi.dao.mysql.PrivatePlayMapper;
import com.chaoyi.model.PrivatePlay;
import com.chaoyi.service.PrivatePlayService;

@Service
public class PrivatePlayServiceImpl implements PrivatePlayService {
	@Resource
	PrivatePlayMapper privatePlayMapper;

	@Override
	public List<PrivatePlay> findList(String offset, String limit) {
		return privatePlayMapper.findList(offset, limit);
	}

	@Override
	public String uploadClassifyImg2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.privatePlayAvatarImgPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.privatePlayAvatarImgPath, fileName);
	}

	@Override
	public String uploadClassifyAudio2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.privatePlayAudioPath,
				fileName);
	}

	@Override
	public int savePrivatePlay(PrivatePlay privatePlay) {
		return privatePlayMapper.savePrivatePlay(privatePlay);
	}

	@Override
	public PrivatePlay findPrivatePlayOne(int id) {
		return privatePlayMapper.findPrivatePlayOne(id);
	}

	@Override
	public int alertSavePrivatePlay(PrivatePlay privatePlay) {
		return privatePlayMapper.alertSavePrivatePlay(privatePlay);
	}

	@Override
	public int deletePrivatePlay(int id) {
		return privatePlayMapper.deletePrivatePlay(id);
	}

	@Override
	public List<PrivatePlay> findAllList() {
		return privatePlayMapper.findAllList();
	}

	@Override
	public int findCount() {
		return privatePlayMapper.findCount();
	}

}
